package com.zq.assistant.ui.widget.recyclerview.adapter;

import android.content.Context;
import android.view.ViewGroup;


import com.zq.assistant.func.ChooseModeController;
import com.zq.assistant.ui.widget.recyclerview.RecyclerViewHolder;

import java.util.List;

/**
 * Created by zhangqiang on 16-10-10.
 */

public abstract class CommonRecyclerAdapter<T> extends SingleHeaderFooterAdapter<T> {

    private int layoutID;

    private MultiTypeSupport<T> multiTypeSupport;
    private ChooseModeController<T> chooseModeController;

    public CommonRecyclerAdapter(List<T> dataList, Context context, int layoutID) {
        this(dataList, context, layoutID,0,0);
    }

    public CommonRecyclerAdapter(List<T> dataList, Context context, int layoutID, int headerLayoutID, int footerLayoutID) {
        super(dataList, context,headerLayoutID,footerLayoutID);
        this.layoutID = layoutID;
    }

    public CommonRecyclerAdapter(List<T> dataList, Context context, int headerLayoutID, int footerLayoutID,MultiTypeSupport<T> multiTypeSupport) {
        super(dataList, context,headerLayoutID,footerLayoutID);
        this.multiTypeSupport = multiTypeSupport;
    }

    public CommonRecyclerAdapter(List<T> dataList, Context context,MultiTypeSupport<T> multiTypeSupport) {
        this(dataList, context,0,0,multiTypeSupport);
    }

    @Override
    public RecyclerViewHolder onCreateContentViewHolder(ViewGroup parent, int viewType) {

        if(multiTypeSupport != null){
            return RecyclerViewHolder.create(context,multiTypeSupport.getLayoutId(viewType),parent);
        }
        return RecyclerViewHolder.create(context,layoutID,parent);
    }

    @Override
    public int getContentItemViewType(int position) {

        if(multiTypeSupport != null){
            return multiTypeSupport.getItemViewType(position,getDataAt(position));
        }
        return super.getContentItemViewType(position);
    }

    public ChooseModeController<T> getChooseModeController(){

        if(chooseModeController == null){
            chooseModeController = new ChooseModeController<>();
        }
        return chooseModeController;
    }

}
